package com.googlecode.todo_robot.frontend.client.view;

import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.resources.client.CssResource;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.*;
import com.googlecode.todo_robot.frontend.client.model.Todo;

/**
 * @author Fuad Ibrahimov
 * @since 30.12.2009
 */
public class TodoItemReadonlyView extends Composite {

  public TodoItemReadonlyView(Todo todo) {
    initWidget(uiBinder.createAndBindUi(this));

    todoContainer.getElement().setId(TODO_ITEM + todo.getKey());
    todoContainer.getElement().addClassName(toStyle(todo.getPriority()));
    dueDate.setText(DateTimeFormat.getMediumDateFormat().format(todo.getDueDate()));
    text.setText(todo.getText());
  }

  private String toStyle(Todo.Priority priority) {
    switch(priority) {
      case HIGH: return style.priorityHigh();
      case MEDIUM: return style.priorityMedium();
      case LOW: return style.priorityLow();
      default: return style.priorityNone();
    }
  }

  @UiField
  HTMLPanel todoContainer;

  @UiField
  SimpleCheckBox doneCheckBox;

  @UiField
  InlineLabel dueDate;

  @UiField
  InlineLabel text;

  @UiField
  Style style;

  private static TodoItemReadonlyUiBinder uiBinder = GWT.create(TodoItemReadonlyUiBinder.class);
  private static final String TODO_ITEM = "todoItem-";

  interface TodoItemReadonlyUiBinder extends UiBinder<Widget, TodoItemReadonlyView> {}
  interface Style extends CssResource {
    String todoItem();
    String readOnlyDate();
    String priorityHigh();
    String priorityMedium();
    String priorityLow();
    String priorityNone();
  }
  

}
